class Solution:
    def largestDivisibleSubset(self, nums):
        if len(nums)<=1:
            return nums
        dp = [None] * len(nums)
        nums.sort()
        maxSet = set()
        for i in range(len(nums)):
            dp[i] = set()
            dp[i].add(nums[i])
            for j in range(i-1, -1, -1):
                if nums[i]%nums[j]==0:
                    tmp= dp[j].copy()
                    tmp.add(nums[i])
                    dp[i] = dp[i] if len(dp[i]) > len(tmp) else tmp

            maxSet = dp[i] if len(dp[i]) > len(maxSet) else maxSet
        return list(maxSet)




if __name__ == '__main__':
    so = Solution()
    x = [4,8,10,240]
    r = so.largestDivisibleSubset(x)
    print(r)
